package other;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

public class IncreasingPrimesNormalizer {
	public static void main(String[] args) throws Exception {

		String sourceFiles = "/home/gmarcone/Descargas/primes/";
		String destFiles = "/home/gmarcone/Descargas/primes/customprimes/";
		String EOL = System.getProperty("line.separator");

		FileWriter fw = null;
		int k = 1;
		int escritos = 0;

		for (int i = 1; i <= 50; i++) {

			if (fw == null) {
				fw = new FileWriter(destFiles + "primes" + k + ".txt");
			}

			File sourceFile = new File(sourceFiles + "primes" + i + ".txt");
			BufferedReader br = new BufferedReader(new FileReader(sourceFile));

			// ignore first line
			br.readLine();

			String line = null;
			while ((line = br.readLine()) != null) {
				String[] split = line.split(" ");

				for (int j = 0; j < split.length; j++) {
					int n = 0;

					try {
						n = Integer.valueOf(split[j]);
					} catch (Exception e) {

					}

					if (n != 0) {
						fw.write(String.valueOf(n));
						escritos++;
						if (escritos == 10) {
							escritos = 0;
							fw.write(EOL);
						} else {
							fw.write(" ");
						}
					}
				}
			}

			br.close();

			if (i % 10 == 0) {
				fw.flush();
				fw.close();
				fw = null;
				k++;
			}
		}

	}
}